package cn.itsource.org.service.impl;

import cn.itsource.base.util.PageBean;
import cn.itsource.org.domain.Department;
import cn.itsource.org.domain.Employee;
import cn.itsource.org.domain.Shop;
import cn.itsource.org.mapper.EmployeeMapper;
import cn.itsource.org.query.EmployeeQuery;
import cn.itsource.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    @Transactional
    public void save(Employee emp) {
        employeeMapper.save(emp);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        employeeMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(Employee emp) {
        employeeMapper.update(emp);
    }

    @Override
    public Employee findById(Long id) {
        return employeeMapper.findById(id);
    }

    @Override
    public List<Employee> findAll() {
        return employeeMapper.findAll();
    }

    @Override
    public Integer queryCount(EmployeeQuery query) {
        return employeeMapper.queryCount(query);
    }

    @Override
    public PageBean<Employee> queryData(EmployeeQuery query) {
        Integer count = employeeMapper.queryCount(query);
        if(count<=0){
            return new PageBean<>();
        }
        List<Employee> list = employeeMapper.queryData(query);

        return new PageBean<Employee>(count,list);
    }

    @Override
    public void patch(List<Long> ids) {
        employeeMapper.patch(ids);
    }

    @Override
    public List<Department> getDeptsOfEmps() {
        return employeeMapper.getDeptsOfEmps();
    }

    @Override
    public List<Shop> getShopsOfEmps() {
        return employeeMapper.getShopsOfEmps();
    }
}
